/**
 * 应用计时器工作线程，停止时返回timeout
 */

var lockedTime;
var timer = 0;

function timeCount() {
	timer ++;
	setTimeout('timeCount()', 1000);
	if(timer >= lockedTime) {
		timer = 0;
		postMessage('timeout');
	} else {
		postMessage(timer);
	}
}

onmessage = function(event) {
	if(event.data == '') {
		timer = 0;
	} else {
		lockedTime = event.data;
		timeCount();
	}
}